#include "KillingFloor.h"
#include "Conversion.h"

KillingFloor::KillingFloor(b2World* world, const Tmx::Object* object) {
	m_contacting = false;
	type = KILLING_FLOOR;

	b2BodyDef groundBodyDef; 
	b2Vec2 groundPosition = sfmlToBox2dPosition(sf::Vector2f(static_cast<float>(object->GetX()) + (static_cast<float>(object->GetWidth())/2), 
		static_cast<float>(object->GetY()) + (static_cast<float>(object->GetHeight())/2)));
	groundBodyDef.position.Set(groundPosition.x, groundPosition.y);

	b2Body* groundBody = world->CreateBody(&groundBodyDef);

	b2PolygonShape groundBox;
	float groundWidth = sfmlToBox2dLength(static_cast<float>(object->GetWidth())/2);
	float groundHeight = sfmlToBox2dLength(static_cast<float>(object->GetHeight())/2);
	groundBox.SetAsBox(groundWidth, groundHeight); 

	b2FixtureDef fixture;
	fixture.shape = &groundBox;
	fixture.density = 1.0f;

	fixture.isSensor = true;

	groundBody->CreateFixture(&fixture);
	groundBody->SetUserData(this);

	printf("Killing floor fixture created\n");
}

void KillingFloor::startContact() {
	m_contacting = true;

	printf("Dying falling\n");
}

void KillingFloor::endContact() {
	m_contacting = false;
}